package com.platform.mobile.operator;

import java.util.LinkedHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.platform.base.SysException;
import com.platform.mobile.bean.GetFollowedByRecrodRequest;
import com.platform.mobile.bean.GetFollowedByRecrodResponse;
import com.platform.mobile.bean.LoginAssitantInfo;
import com.platform.mobile.bean.ReqBean;
import com.platform.mobile.bean.ResBean;
import com.platform.mobile.bean.ResultBean;
import com.platform.mobile.factory.Operator;
import com.platform.mobile.service.PaitentService;
import com.platform.mobile.session.SessionManager;

/**
 * 根据住院信息ID获取回访列表
 * @author inven
 *
 */
@Component
public class GetFollowedByRecord extends Operator{

	private static Logger log = LoggerFactory.getLogger(GetFollowedByRecord.class);
	
	@Autowired
	private PaitentService service;
	
	@SuppressWarnings("unchecked")
	@Override
	public ResBean operate(ReqBean reqBean) throws SysException {
		
		log.info("进入到GetFollowedByRecord业务处理类，处理[" + reqBean.getClientInfo() + "]用户请求");
		ResBean resBean = new ResBean();
		resBean.setClientInfo(reqBean.getClientInfo());
		resBean.setJsonrpc("2.0");
		resBean.setMethod("GetFollowedByRecord");
		ResultBean result = new ResultBean();
		
		GetFollowedByRecrodRequest request = new GetFollowedByRecrodRequest();
		GetFollowedByRecrodResponse response = new GetFollowedByRecrodResponse();
		
		try{
			
			Object params = reqBean.getParams();
			if(params != null){
				
				LinkedHashMap<String, Object> paramMap 
					= (LinkedHashMap<String, Object>)params;
				request.setRecord_id((Integer)paramMap.get("record_id"));
				
				Object session 
					= SessionManager.getInstance()
					.getSessionInfo(reqBean.getSessionID());
				Integer aidId 
					= Integer.parseInt(((LoginAssitantInfo)session).getId());
				
				response = service.getFollowedView(request, aidId);
				
				result.setResultStatus("1");
				result.setInfo("获取住院信息ID为【" + request.getRecord_id() + "】的回访记录成功");
				result.setData(response);
			}
			
		}catch(Exception e){
			result.setResultStatus("0");
			result.setInfo("服务器异常");
			result.setData(null);
		}
		
		resBean.setResult(result);
		return resBean;
	}

}
